<script setup lang="ts">
  import { ref, defineProps, reactive, defineExpose } from "vue"
  import { createMessage } from '@/Public-UIlibrary/pb-message/method'
  import { getLevelEdit } from '@/api/Level'
  let props = defineProps({
    levelList: {
      type: Array,
      default: () => []
    }
  })
  let emits = defineEmits('onConfirmModal')
  let loading = ref(false)
  let LevelFrom = ref({
    tenantLevelId: "",
    tenantLevelRelationId: "",
    tenantLevelName: "",
    description: "",
  })

  const LevelFromRef = ref()
  let LevelModalShow = ref(false)
  const onShow = (row) => {
    console.log(123);

    if (row) {
      let { parentTenantLevelName, createTime, ...needFrom } = row
      LevelFrom.value = { ...needFrom }
    }
    LevelModalShow.value = true
  }
  const onConfirmFn = () => {
    LevelFromRef.value.validate((valid) => {
      if (valid) {
        getLevelEditApi()
      } else {

      }
    })
  }
  const getLevelEditApi = async () => {
    loading.value = true
    let res = await getLevelEdit({ ...LevelFrom.value })
    loading.value = false
    if (res.code == 2000) {
      createMessage({
        message: '编辑成功',
        type: 'success',
      })
      LevelModalShow.value = false
      emits('onConfirmModal')
    }


  }
  defineExpose({ onShow })
</script>

<template>
  <pb-popup v-model="LevelModalShow" :title="LevelFrom.tenantLevelId ? '编辑' : '新增'" Width="365"
    @confirmFn="onConfirmFn">
    <el-form :model="LevelFrom" ref="LevelFromRef" label-width="auto" v-loading="loading">
      <el-form-item label="应用名称" prop="tenantLevelName" :rules="[
        {
          required: true,
          message: '请输入应用名称名称',
          trigger: 'blur',
        }, ]">
        <pb-input v-model=" LevelFrom.tenantLevelName" placeholder="请输入餐段名称" />
      </el-form-item>
      <el-form-item label="所属层级" prop="tenantLevelName" :rules="[
              {
                required: true,
                message: '请选择所属层级',
                trigger: 'blur',
              }, ]">
        <pb-select v-model="LevelFrom.tenantLevelId" placeholder="请选择所属层级" keys="tenantLevelId" label="tenantLevelName"
          :options="levelList" />
      </el-form-item>
    </el-form>
  </pb-popup>
</template>

<style lang="less" scoped>

</style>